﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;

namespace RiskMan.DataClass.Models.Plaza_II.FortsFutInfoRepl
{
    /// <summary>
    /// Таблица 35. Поля таблицы fut_vcb -  Справочник торгуемых активов
    /// </summary>
    public class FutVcb : INotifyPropertyChanged
    {
        #region private

        private long _replId;
        private long _replRev;
        private long _replAct;
        private string _codeVcb;
        private string _name;
        private string _execType;
        private string _curr;
        private Decimal _exchPay;
        private int _exchPayScalped;
        private Decimal _clearPay;
        private int _celarPayScalped;
        private Decimal _sellFee;
        private Decimal _buyFee;
        private string _tradeScheme;
        private string _section;
        private Decimal _exchPaySpot;
        private string _clientCode;
        private Decimal _exchPaySpotRepo;
        private int _rateId;

        #endregion

        #region public

        /// <summary>
        /// Служебное поле подсистемы репликации
        /// </summary>
        public long ReplId
        {
            get { return _replId; }
            set
            {
                if (_replId != value)
                {
                    _replId = value;
                    RaisePropertyChanged("ReplId");
                }
            }
        }

        /// <summary>
        /// Служебное поле подсистемы репликации
        /// </summary>
        public long ReplRev
        {
            get { return _replRev; }
            set
            {
                if (_replRev != value)
                {
                    _replRev = value;
                    RaisePropertyChanged("ReplRev");
                }
            }
        }

        /// <summary>
        /// Служебное поле подсистемы репликации
        /// </summary>
        public long ReplAct
        {
            get { return _replAct; }
            set
            {
                if (_replAct != value)
                {
                    _replAct = value;
                    RaisePropertyChanged("ReplAct");
                }
            }
        }

        /// <summary>
        /// Код базового актива
        /// </summary>
        public string CodeVcb
        {
            get { return _codeVcb; }
            set
            {
                if (_codeVcb != value)
                {
                    _codeVcb = value;
                    RaisePropertyChanged("CodeVcb");
                }
            }
        }

        /// <summary>
        /// Наименование
        /// </summary>
        public string Name
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    _name = value;
                    RaisePropertyChanged("Name");
                }
            }
        }

        /// <summary>
        /// Тип исполнения
        /// • Поле exec_type может принимать следующие значения:
        ///A Альтернативный
        ///D Поставка
        ///I Индекс
        /// S RTS Standard
        /// </summary>
        public string ExecType
        {
            get { return _execType; }
            set
            {
                if (_execType != value)
                {
                    _execType = value;
                    RaisePropertyChanged("ExecType");
                }
            }
        }

        /// <summary>
        /// Валюта платежа
        /// </summary>
        public string Curr
        {
            get { return _curr; }
            set
            {
                if (_curr != value)
                {
                    _curr = value;
                    RaisePropertyChanged("Curr");
                }
            }
        }

        /// <summary>
        /// Биржевой сбор за 1 контракт в рублях
        /// </summary>
        public Decimal ExchPay
        {
            get { return _exchPay; }
            set
            {
                if (_exchPay != value)
                {
                    _exchPay = value;
                    RaisePropertyChanged("ExchPay");
                }
            }
        }

        /// <summary>
        /// Признак скальпирования биржевого сбора
        /// </summary>
        public int ExchPayScalped
        {
            get { return _exchPayScalped; }
            set
            {
                if (_exchPayScalped != value)
                {
                    _exchPayScalped = value;
                    RaisePropertyChanged("ExchPayScalped");
                }
            }
        }

        /// <summary>
        /// Клиринговый сбор за 1 контракт в рублях
        /// </summary>
        public Decimal ClearPay
        {
            get { return _clearPay; }
            set
            {
                if (_clearPay != value)
                {
                    _clearPay = value;
                    RaisePropertyChanged("ClearPay");
                }
            }
        }

        /// <summary>
        /// Признак скальпирования клирингового сбора
        /// </summary>
        public int CelarPayScalped
        {
            get { return _celarPayScalped; }
            set
            {
                if (_celarPayScalped != value)
                {
                    _celarPayScalped = value;
                    RaisePropertyChanged("CelarPayScalped");
                }
            }
        }

        /// <summary>
        /// Комиссия с продавца. Не используется
        /// </summary>
        public Decimal SellFee
        {
            get { return _sellFee; }
            set
            {
                if (_sellFee != value)
                {
                    _sellFee = value;
                    RaisePropertyChanged("SellFee");
                }
            }
        }

        /// <summary>
        /// Комиссия с покупателя. Не используется
        /// </summary>
        public Decimal BuyFee
        {
            get { return _buyFee; }
            set
            {
                if (_buyFee != value)
                {
                    _buyFee = value;
                    RaisePropertyChanged("BuyFee");
                }
            }
        }

        /// <summary>
        /// Форма торгов
        /// • Поле trade_scheme может принимать следующие значения:
        /// F С полным обеспечением
        /// G С залогом
        /// </summary>
        public string TradeScheme
        {
            get { return _tradeScheme; }
            set
            {
                if (_tradeScheme != value)
                {
                    _tradeScheme = value;
                    RaisePropertyChanged("TradeScheme");
                }
            }
        }

        /// <summary>
        /// Наименование Секции
        /// </summary>
        public string Section
        {
            get { return _section; }
            set
            {
                if (_section != value)
                {
                    _section = value;
                    RaisePropertyChanged("Section");
                }
            }
        }

        /// <summary>
        /// Биржевой сбор по Спотам за 1 лот в % от цены
        /// </summary>
        public Decimal ExchPaySpot
        {
            get { return _exchPaySpot; }
            set
            {
                if (_exchPaySpot != value)
                {
                    _exchPaySpot = value;
                    RaisePropertyChanged("ExchPaySpot");
                }
            }
        }

        /// <summary>
        /// Код клиента
        /// </summary>
        public string ClientCode
        {
            get { return _clientCode; }
            set
            {
                if (_clientCode != value)
                {
                    _clientCode = value;
                    RaisePropertyChanged("ClientCode");
                }
            }
        }

        /// <summary>
        /// Биржевой сбор по Репо
        /// </summary>
        public Decimal ExchPaySpotRepo
        {
            get { return _exchPaySpotRepo; }
            set
            {
                if (_exchPaySpotRepo != value)
                {
                    _exchPaySpotRepo = value;
                    RaisePropertyChanged("ExchPaySpotRepo");
                }
            }
        }

        /// <summary>
        /// Идентификатор курса
        /// </summary>
        public int RateId
        {
            get { return _rateId; }
            set
            {
                if (_rateId != value)
                {
                    _rateId = value;
                    RaisePropertyChanged("RateId");
                }
            }
        }
        #endregion


        #region event PropertyChangedEventHandler

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region processing
        public static FutVcb ParseFutVcb(Dictionary<String, String> relation)
        {
            FutVcb tmp = new FutVcb();
            tmp.Parse(relation);
            return tmp;
        }

        public void Parse(Dictionary<String, String> relation)
        {
            foreach (String field in relation.Keys)
            {
                String value = relation[field];

                switch (field)
                {
                    case "replID": long.TryParse(value, out _replId); break;
                    case "replRev": long.TryParse(value, out _replRev); break;
                    case "replAct": long.TryParse(value, out _replAct); break;
                    case "code_vcb": _codeVcb = value; break;
                    case "name": _name = value; break;
                    case "exec_type": _execType = value; break;
                    case "curr": _curr = value; break;
                    case "exch_pay": Decimal.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en-US"), out _exchPay); break;
                    case "exch_pay_scalped": int.TryParse(value, out _exchPayScalped); break;
                    case "clear_pay": Decimal.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en-US"), out _clearPay); break;
                    case "celar_pay_scalped": int.TryParse(value, out _celarPayScalped); break;
                    case "sell_fee": Decimal.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en-US"), out _sellFee); break;
                    case "buy_fee": Decimal.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en-US"), out _buyFee); break;
                    case "trade_scheme": _tradeScheme = value; break;
                    case "section": _section = value; break;
                    case "exch_pay_spot": Decimal.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en-US"), out _exchPaySpot); break;
                    case "client_code": _clientCode = value; break;
                    case "exch_pay_spot_repo": Decimal.TryParse(value, NumberStyles.Number, CultureInfo.GetCultureInfo("en-US"), out _exchPaySpotRepo); break;
                    case "rate_id": int.TryParse(value, out _rateId); break; 

                };
            }
        }

        public static void AddValueToObsColFutVcb(FutVcb inst)
        {
            MainWindow.StaticLevel._dataProvider.FutVcbList.Add(inst);
        }
        #endregion
    }
}
